<template>
	<view class="integral">
		<view class="head">
			<view class="text">
				<view>
					<view>当前积分</view>
					<view class="num">{{infoIntegral.ava}}<image src="/static/images/index/integral_icon.png" mode="widthFix"></image></view>
				</view>
			</view>
		</view>
		<view class="menu_box">
			<view class="menu">
				<view class="nav">
					<view>
						<view class="label">累计获得</view>
						<view class="val">{{infoIntegral.in}}</view>
					</view>
				</view>
				<view class="hr"></view>
				<view class="nav">
					<view>
						<view class="label">累计使用</view>
						<view class="val">{{infoIntegral.out}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="teamList_box">
			<view class="teamListTitle">近30天记录<view class="more" @click="goMore">查看更多 > </view>
			</view>
			<view v-if="integralList.length > 0">
				<tui-list-view backgroundColor="#fff">
					<tui-list-cell v-for="(item,index) in integralList" :key="index">
						<view class="teamList">
							<view class="label">
								<view class="text">
									<view class="h1">{{item.comment}}</view>
									<view class="h2">{{item.useTime}}</view>
								</view>
							</view>
							<view class="val">
								<view class="text" v-if="item.isDeduct == 0" style="color: #F5A649;">
									+{{item.point}}
								</view>
								<view class="text" v-if="item.isDeduct == 1" style="color: #111;">
									-{{item.point}}
								</view>
							</view>
						</view>
					</tui-list-cell>
				</tui-list-view>
			</view>
			<view v-else-if="integralList.length == 0">
				<tui-no-data style="margin-top: 300rpx;" imgUrl="/static/images/mall/my_course_empty.png">暂无数据</tui-no-data>
			</view>
		</view>
		<!--加载loadding-->
		<tui-loadmore v-if="loadding" :index="3" type="red"></tui-loadmore>
		<tui-nomore v-if="!pullUpOn" backgroundColor="#f7f7f7"></tui-nomore>
		<!--加载loadding-->
	</view>
</template>

<script>
	const util = require("@/utils/util.js")
	const app = getApp()
	export default {
		name: '',
		components: {

		},
		props: {

		},
		data() {
			return {
				integralList: [], // 积分列表
				infoIntegral: {}, // 积分信息

				current: 1,
				pages: '',
				loadding: false,
				pullUpOn: true,
			};
		},
		computed: {

		},
		watch: {

		},
		onLoad() {
			this.getList();
		},
		onShow() {

		},
		onPullDownRefresh: function() {
			this.current = 1;
			this.pullUpOn = true;
			this.loadding = false;
			this.getList();
			uni.stopPullDownRefresh();
		},
		onReachBottom: function() {
			this.loadding = true;
			if (this.current == this.pages) {
				this.loadding = false;
				this.pullUpOn = false;
			} else {
				this.getList(true);
				this.loadding = false;
			}
		},
		methods: {
			// 积分记录列表
			getList(selet_type) {
				let that = this;
				let loadData;
				that.pullUpOn = true;
				if (selet_type) {
					loadData = JSON.parse(JSON.stringify(that.integralList));
					that.current = that.current + 1;
				}
				util.request('my/pointRecord', {
					current: that.current,
					userDate: ""
				}, 'POST' , 'application/json').then(res => {
					if (res.code == 0) {
						that.getIntegral();
						that.integralList = res.data.records
						that.pages = res.data.pages
						if (selet_type) {
							that.integralList = loadData.concat(res.data.records);
						}
					}
				});
			},
			// 我的积分
			getIntegral() {
				util.request('my/pointStatics', {}, 'POST').then(res => {
					if (res.code == 0) {
						this.infoIntegral = res.data
					}
				});
			},
			// 查看更多
			goMore() {
				uni.navigateTo({
					url: "./record"
				});
			}
		},
	};
</script>

<style lang="scss">
	.integral {
		.head {
			width: 100%;
			height: 340rpx;
			position: relative;
			z-index: 0;
			background: linear-gradient(155deg, #FEBB5C, #FDCC89);

			.text {
				width: 100%;
				position: relative;
				z-index: 1;
				padding: 80rpx 60rpx 0;
				font-size: 26rpx;
				color: #fff;
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				.num {
					font-size: 64rpx;
				}

				image {
					width: 50rpx;
					height: 50rpx;
					vertical-align: middle;
					margin: -8rpx 0 0 16rpx;
				}
			}
		}
		.menu_box {
			padding: 0 30rpx 0;
			position: relative;
			z-index: 1;
			margin-top: -90rpx;
			.menu {
				width: 100%;
				display: flex;
				align-items: center;
				background: #fff;
				border-radius: 16rpx;
			
				.nav {
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: center;
					height: 140rpx;
					text-align: center;
			
					.label {
						font-size: 26rpx;
						color: #666666;
					}
					
					.val {
						font-size: 36rpx;
						font-weight: bold;
						color: #111111;
					}
				}
				.hr {
					width: 2rpx;
					height: 40rpx;
					background: #EAE9E8;
				}
			}
		}
		
		.teamList_box {
			padding: 20rpx 30rpx 0;
			.teamListTitle {
				// background: none;
			}
			
			.teamList {
			
				.btn {
					padding: 10rpx 30rpx;
				}
			
				.btnA {
					background: gray;
				}
			}
		}
	}
</style>
